import { apiGetCates, apiPostCreateCates, apiDeleteCate } from '@/api/CategoriesManagement/index'

export default {
  methods: {
    getCates(userId, params) {
      apiGetCates(userId, params).then(res => {
        // console.log('apiGetCates', res);
        const data = res.content || []
        this.pagination.total = res.page.totalElements || 0
        this.tableData = Object.freeze(data)
        this.tableLoading = false
      })
        .catch(err => {
          // console.log(err);
          this.tableData = []
          this.pagination.total = 0
          this.tableLoading = false
        })
    },

    createCate(data) {
      apiPostCreateCates(data).then(res => {
        // console.log('apiPostCreateCates', res);
        this.$message.success('新增成功')
        this.handleFormSubmit()
        this.handleDialogClose()
      }).catch(err => {
        console.log('err', err);
        this.$message.error('新增失败')
      })
    },

    deleteCate(classID, userID) {
      apiDeleteCate(classID, userID).then(res => {
        console.log('apiDeleteCate', res)
        if (res && res.message) {
          this.$message.error(res.message)
        }
      })
        .catch(err => {
          this.$message.success('删除成功')
          this.handleFormSubmit();
        })
    }
  }
}